﻿#region File Description
//-----------------------------------------------------------------------------
// PauseMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
#endregion

namespace DungDungShit
{
    /// <summary>
    /// The pause menu comes up over the top of the game,
    /// giving the player options to resume or quit.
    /// </summary>
    class PauseMenuScreen : MenuScreen
    {
        private int slotNumber;
        MapContainer mapContainer;

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public PauseMenuScreen(int slotNumber = 0)
            : base("Paused")
        {
            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("Resume");
            MenuEntry restartGameMenuEntry = new MenuEntry("Restart");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit");

            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;
            restartGameMenuEntry.Selected += restartGameMenuEntry_Selected;
            quitGameMenuEntry.Selected += quitGameMenuEntry_Selected;

            // Add entries to the menu.
            menuEntries.Add(resumeGameMenuEntry);
            menuEntries.Add(restartGameMenuEntry);
            menuEntries.Add(quitGameMenuEntry);

            this.slotNumber = slotNumber;
        }
        public PauseMenuScreen(int slotNumber, MapContainer mapContainer)
            : base("Paused")
        {
            // Create our menu entries.
            MenuEntry resumeGameMenuEntry = new MenuEntry("Resume");
            MenuEntry restartGameMenuEntry = new MenuEntry("Restart");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit");

            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += OnCancel;
            restartGameMenuEntry.Selected += restartGameMenuEntry_Selected;
            quitGameMenuEntry.Selected += quitGameMenuEntry_Selected;

            // Add entries to the menu.
            menuEntries.Add(resumeGameMenuEntry);
            menuEntries.Add(restartGameMenuEntry);
            menuEntries.Add(quitGameMenuEntry);

            this.slotNumber = slotNumber;
            this.mapContainer = mapContainer;
        }

        protected override void OnCancel()
        {
            mapContainer.isPaused = false;
            base.OnCancel();
        }


        #endregion

        #region Handle Input

        /// <summary>
        /// Event handler for when the Restart Game menu entry is selected.
        /// </summary>
        protected void restartGameMenuEntry_Selected(object sender, EventArgs e)
        {
            const string message = "Are you sure you want to restart this game?";

            MessageBoxScreen confirmRestartMessageBox = new MessageBoxScreen(message);

            confirmRestartMessageBox.Accepted += confirmRestartMessageBox_Accepted;

            ScreenManager.AddScreen(confirmRestartMessageBox);
        }

        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to restart" message box. This uses the loading screen to
        /// transition from the game back to the new game screen.
        /// </summary>
        protected void confirmRestartMessageBox_Accepted(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, new GameScreen(slotNumber));
        }


        /// <summary>
        /// Event handler for when the Quit Game menu entry is selected.
        /// </summary>
        protected void quitGameMenuEntry_Selected(object sender, EventArgs e)
        {
            const string message = "Are you sure you want to quit this game?";

            MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);

            confirmQuitMessageBox.Accepted += confirmQuitMessageBox_Accepted;

            ScreenManager.AddScreen(confirmQuitMessageBox);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to quit" message box. This uses the loading screen to
        /// transition from the game back to the main menu screen.
        /// </summary>
        protected void confirmQuitMessageBox_Accepted(object sender, EventArgs e)
        {
            LoadingScreen.Load(ScreenManager, false, new MainMenuScreen());
        }


        #endregion
    }
}
